package top.xiaocao.jpa.service;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import top.xiaocao.jpa.model.Address;
import top.xiaocao.jpa.model.User;

@Service
public class TransactionServiceImpl implements TransactionService {
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private AddressService addressService;

	@Override
	@Transactional
	public void add(User user, Address address) {
		userService.add(user);
		address.setUserId(user.getId());
		addressService.add(address);
	}

	@Override
	//@Transactional
	public void addAndThrowException(User user, Address address) {
		userService.addWithoutTransaction(user);
		address.setUserId(user.getId());
		addressService.addAndThrowException(address);
	}

}
